package com.evil.application.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.evil.application.pojo.dto.robot.log.RobotLogReqDTO;
import com.evil.application.pojo.dto.robot.log.RobotLogRespDTO;
import com.evil.application.pojo.entity.ApplicationRobotLog;
import com.evil.common.core.entity.QueryModel;
import com.evil.common.core.enums.RCodeEnum;
import com.evil.common.core.exception.BusinessException;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.apache.ibatis.annotations.Param;

import java.util.List;
import java.util.Optional;

/**
 * 应用机器人日志表
 *
 * @author liyang
 * @date 2023-01-30 14:49
 */
public interface ApplicationRobotLogMapper extends BaseMapper<ApplicationRobotLog> {

    default Optional<ApplicationRobotLog> isExistById(Long id) {
        return Optional.ofNullable(this.selectById(id));
    }

    default ApplicationRobotLog findById(Long id) {
        return this.isExistById(id).orElseThrow(() -> new BusinessException(RCodeEnum.ROBOT_LOG_NOT_EXIST));
    }

    int updateBatch(List<ApplicationRobotLog> list);

    int batchInsert(@Param("list") List<ApplicationRobotLog> list);

    List<RobotLogRespDTO> robotLogs(RobotLogReqDTO robotLogReqDTO);

    default PageInfo<RobotLogRespDTO> robotLogPage(QueryModel<RobotLogReqDTO> queryModel) {
        return PageHelper.startPage(queryModel.getPageNum(), queryModel.getPageSize(), queryModel.initOrder())
                .doSelectPageInfo(() -> this.robotLogs(queryModel.getParam()));
    }
}